package system

import (
	"context"

	"go_admin/api/system/v1"
	"go_admin/internal/service"
)

func (c *ControllerV1) RoleList(ctx context.Context, req *v1.RoleListReq) (res *v1.RoleListRes, err error) {
	res, err = service.SysRole().GetRoleListSearch(ctx, req)
	return
}
func (c *ControllerV1) RoleGetParams(ctx context.Context, req *v1.RoleGetParamsReq) (res *v1.RoleGetParamsRes, err error) {
	res = new(v1.RoleGetParamsRes)
	res.Menu, err = service.SysAuthRule().GetMenuList(ctx)
	return
}
func (c *ControllerV1) RoleAdd(ctx context.Context, req *v1.RoleAddReq) (res *v1.RoleAddRes, err error) {
	err = service.SysRole().AddRole(ctx, req)
	return
}
func (c *ControllerV1) RoleGet(ctx context.Context, req *v1.RoleGetReq) (res *v1.RoleGetRes, err error) {
	res = new(v1.RoleGetRes)
	res.Role, err = service.SysRole().Get(ctx, req.Id)
	if err != nil {
		return
	}
	res.MenuIds, err = service.SysRole().GetFilteredNamedPolicy(ctx, req.Id)
	return
}
func (c *ControllerV1) RoleEdit(ctx context.Context, req *v1.RoleEditReq) (res *v1.RoleEditRes, err error) {
	err = service.SysRole().EditRole(ctx, req)
	return
}
func (c *ControllerV1) RoleDelete(ctx context.Context, req *v1.RoleDeleteReq) (res *v1.RoleDeleteRes, err error) {
	err = service.SysRole().DeleteByIds(ctx, req.Ids)
	return
}
